package com.javasm.adminapi.module.priceadjust.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.javasm.adminapi.module.priceadjust.dao.GgPriceAdjustDao;
import com.javasm.adminapi.module.priceadjust.dto.SearchDTO;
import com.javasm.adminapi.module.priceadjust.entity.GgPriceAdjust;
import com.javasm.adminapi.module.priceadjust.service.GgPriceAdjustService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 商品管理-价格调整(GgPriceAdjust)表服务实现类
 *
 * @author makejava
 * @since 2025-10-16 20:52:04
 */
@Service("ggPriceAdjustService")
public class GgPriceAdjustServiceImpl extends ServiceImpl<GgPriceAdjustDao, GgPriceAdjust> implements GgPriceAdjustService {


    @Resource
    GgPriceAdjustDao priceAdjustDao;
    @Override
    public PageInfo<GgPriceAdjust> listByCondition(SearchDTO dto) {
        Integer pageNum = dto.getPageNum();
        if (pageNum==null){
            pageNum=1;
        }
        Integer pageSize = dto.getPageSize();
        if (pageSize==null){
            pageNum=3;
        }
        PageHelper.startPage(pageNum,pageSize);
        List<GgPriceAdjust> list = priceAdjustDao.selectByCondition(dto);
        PageInfo<GgPriceAdjust> pageInfoList = new PageInfo<>(list);
        return pageInfoList;
    }

    @Override
    public void saveOrUpdateWithTime(GgPriceAdjust priceAdjust) {
        //TODO从springSecurity框架中获取到当前用户的信息，塞入priceAdjust的applyUser中 如果为空就证明没有登录，抛异常未登录，然后返回给前端
        //TODO 前端拿到异常跳转到登陆页面
        //如果登陆了在执行以下代码

        priceAdjust.setUpdateTime(new Date());
        //判断是否有主键，有主键是修改，没有是新增
        if (priceAdjust.getId()==null){
            //是新增
            priceAdjust.setCreateTime(new Date());
        }
        saveOrUpdate(priceAdjust);
    }
}

